<div id="petition-tool" class="tool <%= 'un' unless current_user.try(:signed?, @actionPage.petition) || params[:thankyou] -%>signed" data-petition-id="<%= @actionPage.petition.id %>">
  <div class="tool-container">

    <div class="tool-heading">
      <h2 class="tool-title signed">
        <span class='glyphicon glyphicon-ok'></span>Signed
      </h2>
      <h2 class="tool-title unsigned">
        <%= t :sign_the_petition -%>
      </h2>
    </div>

    <div class="tool-body">
      <%- if @petition.enable_affiliations -%>
        <div class='small tool-notice'>
          <%= t :name_and_affiliations_published -%>
        </div>
      <% end %>

      <%- if @actionPage.petition.goal -%>
        <div id="progress-bar">
          <div class='count'><b><%= @signature_count -%></b> /
            <span class='goal'><%= @actionPage.petition.goal -%> <%= t :signatures -%></span>
          </div>
          <div class="progress">
            <div class="progress-bar progress-bar-danger signatures-bar" role="progressbar" aria-valuenow="<%= @signature_count -%>>" aria-valuemin="0" aria-valuemax="<%= @actionPage.petition.goal-%>" style="width: <%= @actionPage.petition.percent_complete -%>%">
            </div>
          </div>
        </div>
      <% else %>
        <div id="progress-bar">
          <div class='count'><b><%= @signature_count -%></b><span class='goal'> <%= t :signatures -%></span>
          </div>
        </div>
      <% end -%>

        <div class='signed'>
          <%= render 'tools/share' -%>
        </div>
        <div class='unsigned'>
          <%= form_for @signature, url: '/tools/petition',
            html: {class: 'petition-tool'} do |f| -%>
            <%= f.hidden_field :petition_id -%>
            <input type="hidden" name="action_id" value="<%= @actionPage.id %>" />

            <fieldset>
              <%= f.email_field :email, required: true,
                class: 'form-control', pattern: '.*\S+.*', title: t('petition_errors.required.email'),
                'aria-label': 'Email', placeholder: 'Email'
              -%>
            </fieldset>
            <fieldset>
              <%= f.text_field :first_name, required: true,
                class: 'form-control', pattern: '.*\S+.*', title: t('petition_errors.required.first_name'),
                'aria-label': t(:first_name), placeholder: t(:first_name)
              -%>
            </fieldset>
            <fieldset>
              <%= f.text_field :last_name, required: true,
                class: 'form-control', pattern: '.*\S+.*', title: t('petition_errors.required.last_name'),
                'aria-label': t(:last_name), placeholder: t(:last_name)
              -%>
            </fieldset>

            <% if @actionPage.petition.enable_affiliations %>
              <div id='affiliations'>
                <%= f.fields_for :affiliations, Affiliation.new do |affiliation| %>
                  <%= render 'affiliations/affiliation_fields', :f => affiliation %>
                <% end %>
                <div class='links text-right with-js'>
                  <%= link_to_add_association t(:add_another_institution), f, :affiliations, partial: 'affiliations/affiliation_fields' %>
                </div>
              </div>
            <% end %>

            <% if @require_location %>
              <%= render 'tools/petition_location', f: f %>
            <% end %>

            <fieldset>
              <% unless @petition.enable_affiliations %>
                <div class='checkbox small'>
                  <%= f.label :anonymous do -%>
                    <%= check_box_tag 'signature[anonymous]' -%>
                    <%= t :dont_show_my_name -%>
                  <% end -%>
                </div>
              <% end %>

              <% unless @require_location %>
                <%= render 'tools/petition_location', f: f %>
              <% end %>
              <%= render "tools/newsletter_signup", email: false, location: false, privacy_notice: false %>
              <%= render 'tools/save_my_info_option', info: t(%w[email name location]) -%>

            </fieldset>

            <%= render "tools/privacy_notice" %>

            <% button_text = params.include?("button_text") ? params["button_text"].to_sym : t(:speak_out) %>
            <%= f.submit button_text, class: 'btn action'-%>
            <%= render 'tools/loading' -%>
          <% end %>
      </div>
    </div>
  </div>
</div>

<% if !@petition.enable_affiliations? -%>
<div id='signatures' class="hidden-xs ajax-update">
  <h4 class='header'><em><%= t :recent_signatories -%></em></h4>
  <%= render(partial: "tools/signatures", layout: false) %>
</div>
<% end -%>
